use "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 3 Background\Data\changeall_indecisos.dta", replace

gen lntime=ln(time)
reg mex2006 lntime
predict mex2006hat if e(sample)==1
reg bra2014 lntime
predict bra2014hat if e(sample)==1
reg bra2002 lntime
predict bra2002hat if e(sample)==1
reg bra2010 lntime
predict bra2010hat if e(sample)==1
reg mex2000 lntime
predict mex2000hat if e(sample)==1

replace mex2006waves="06"
replace bra2002waves="02"
replace bra2014waves="14"
replace bra2010waves="10"
replace mex2000waves="00"

replace mex2006waves="{bf:06}" if time==39
replace mex2000waves="{bf:00}" if time==19
replace bra2002waves="{bf:02}" if time==27
replace bra2014waves="{bf:14}" if time==18
replace bra2010waves="{bf:10}" if time==27
replace mex2012waves="{bf:12}"
replace mex2018waves="{bf:18}"
replace bra2006waves="{bf:06}"
replace arg2015waves="{bf:15}"
replace bra2018waves="{bf:18}"


gen xarrow10s = 22
gen yarrow10s = .385
gen xarrow10e = 22.5
gen yarrow10e = .425
gen xarrow02s = 16.5
gen yarrow02s = .585
gen xarrow02e = 16
gen yarrow02e = .55
gen xarrow14s = 6.3
gen yarrow14s = .5
gen xarrow14e = 7.5
gen yarrow14e = .525
gen xarrow00s = 7
gen yarrow00s = .69
gen xarrow00e = 8
gen yarrow00e = .725
gen xarrow06s = 24.5
gen yarrow06s = .73
gen xarrow06e = 24
gen yarrow06e = .69
gen xarrow06bs = 13
gen yarrow06bs = .508
gen xarrow06be = 12.3
gen yarrow06be = .532
gen xarrow12s = 10.5
gen yarrow12s = .60
gen xarrow12e = 9.5
gen yarrow12e = .557

twoway (scatter bra2002 bra2002hat time, connect(i l) sort(time) lpattern(solid solid) lcolor(black black) lwidth(med med) m(i i) mc(black black)  mlab(bra2002waves) mlabpos(0 0) mlabc(black black)) /// ///
(scatter bra2010 bra2010hat time, connect(i l) sort(time) lpattern(dash dash) lcolor(black black) lwidth(med med) m(i i) mc(black black)  mlab(bra2010waves) mlabpos(0 0) mlabc(black black)) ///
(scatter bra2014 bra2014hat time, connect(i l) sort(time) lpattern(shortdash shortdash) lcolor(black black) lwidth(med med) m(i i) mc(black black)  mlab(bra2014waves) mlabpos(0 0) mlabc(black black)) ///
(scatter mex2000 mex2000hat time, connect(i l) sort(time) lcolor(gs8 gs8) lwidth(med med) m(i i) mc(gs8 gs8) mlab(mex2000waves) mlabpos(0 0) mlabc(gs8 gs8)) ///
(scatter mex2006 mex2006hat time, connect(i l) sort(time) lpattern(dash dash) lcolor(gs8 gs8) lwidth(med med) m(i i) mc(gs8 gs8) mlab(mex2006waves) mlabpos(0 0) mlabc(gs8 gs8)) ///
(scatter bra2006 time, m(i) mc(black)  mlab(bra2006waves) mlabc(black) mlabpos(0)) ///
(scatter mex2012 time, m(i) mc(gs8) mlab(mex2012waves) mlabc(gs8) mlabpos(0)) ///
(scatter mex2018 time, m(i) mc(gs8) mlab(mex2018waves) mlabc(gs8) mlabpos(0)) ///
(scatter arg2015 time, m(i) mc(gs8) mlab(arg2015waves) mlabc(black) mlabpos(0)) ///
(scatter bra2018 time, m(i) mc(black) mlab(bra2018waves) mlabc(black) mlabpos(0)) ///
, /// 
xtitle("{bf:Weeks between Waves}") ytitle("{bf:Percentage of Once- & Twice-Opinionated}" "{bf:Respondents who Maintain Vote Preference }") yscale(range(.3 .8)) graphregion(color(white)) ///
plotregion(lstyle(yxline) lcolor(black)) legend(order(6 "Brazil" 2 "Mexico" ) size(med) rows(2) ///
symxsize(8) keygap(2) colgap(1)) ytick(.3(.1).8) ylabel(.3 "30%" .4 "40%" .5 "50%" .6 "60%" .7 "70%" .8 "80%") ///
legend(order (2 "Brazil 2002" 4 "Brazil 2010" 6 "Brazil 2014" 8 "Mexico 2000" 10 "Mexico 2006") size(medsmall) title("Best-fit Lines", size(medsmall) color(black)))


graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 3 Background\Figures\ChangeFigureIndecisos.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR3_2.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR3_2.pdf", as(pdf) replace 


egen bra=rmax( bra2002 bra2006 bra2010 bra2014)
egen mex=rmax( mex2000 mex2006 mex2012)

/*
text(.608 10.5 "Mexico 2012", size(small) lcolor(white) color(gs8)) ///
(pcarrow yarrow12s xarrow12s yarrow12e xarrow12e, lcolor(gs8) mcolor(gs8)) ///
text(.50 15 "Bra2006", size(small) lcolor(white) color(black))
(pcarrow yarrow06bs xarrow06bs yarrow06be xarrow06be, lcolor(black) mcolor(black)) ///


(pcarrow yarrow10s xarrow10s yarrow10e xarrow10e, lcolor(black) mcolor(black)) ///
(pcarrow yarrow02s xarrow02s yarrow02e xarrow02e, lcolor(black) mcolor(black)) ///
(pcarrow yarrow14s xarrow14s yarrow14e xarrow14e, lcolor(black) mcolor(black)) ///
(pcarrow yarrow00s xarrow00s yarrow00e xarrow00e, lcolor(gs8) mcolor(gs8)) ///
(pcarrow yarrow06s xarrow06s yarrow06e xarrow06e, lcolor(gs8) mcolor(gs8)) ///

ext(.5 4.9 "Bra14", size(small) lcolor(white))  text(.378 22 "Bra10", size(small) lcolor(white)) ///
text(.595 16.5 "Bra02", size(small) lcolor(white)) ///
text(.74 24.5 "Mex06", size(small) lcolor(white) color(gs8))  ///
text(.685 7 "Mex00", size(small) lcolor(white) color(gs8))  
